<template>
  <div class="table-page-search-wrapper">
    <a-card>
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :md="8" :sm="12">
            <a-form-item
                label="学号"
            >
              <a-input v-model="queryParam.xh"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="12">
            <a-form-item
                label="姓名"
            >
              <a-input v-model="queryParam.xm"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="12">
            <a-form-item
              label="论文题目"
            >
              <a-input v-model="queryParam.lwtm"/>
            </a-form-item>
          </a-col>
          <template v-if="advanced">
            <a-col :md="8" :sm="12">
              <a-form-item label="发表日期">
                <a-month-picker style="width: 100%" v-model="queryParam.fbsj"/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="12">
              <a-form-item
                label="学生类别"
              >
                <a-select v-model="queryParam.xslbm">
                  <a-select-option v-for="i in TYPE0075" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="12">
              <a-form-item
                label="学生来源"
              >
                <a-select :allowClear="true" v-model="queryParam.xslxm">
                  <a-select-option v-for="i in TYPE0503" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="12">
              <a-form-item label="院系">
                <a-select allowClear v-model="queryParam.zsyxm" @change="yxChange" showSearch :filterOption="filterOption">
                  <a-select-option v-for="i in selectMenu.yxList" :key="i.id" :value="i.dwh">{{ i.dwh }} {{ i.dwmc }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="12">
              <a-form-item label="专业">
                <a-select allowClear v-model="queryParam.zszym" showSearch :filterOption="filterOption">
                  <a-select-option v-for="i in selectMenu.zyList" :key="i.id" :value="i.zyh">{{ i.zyh}} {{ i.zymc }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="12" :sm="12">
            <span class="table-page-search-submitButtons" >
              <a-button type="primary" @click="$refs.table.refresh(true)" style="margin:0 10px">查询</a-button>
              <a-button type="primary" style="margin:0 10px" @click="exportExcel">导出</a-button>
              <a-button @click="queryParam = {};$refs.table.refresh()" style="margin-left: 8px;">重置</a-button>

              <a @click="advanced = !advanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </a-card>

    <a-card :bordered="false" style="margin-top: 10px">
      <s-table
        ref="table"
        size="default"
        rowKey="id"
        :columns="columns"
        :data="loadData"
        :alert="{show: true}"
        :scroll="{ x: 1800 }"
        :pagination="{ pageSize: 10 }"
      >
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 }}
        </span>
      </s-table>
    </a-card>

  </div>
</template>

<script>
import { STable } from '~'
import { mapState } from 'vuex'
import moment from 'moment';
import { DateToString } from '@/utils/common'

export default {
  data () {
    return {
      advanced: true,
      queryParam: {
        zszym: ''
      },
      columns: [
        {
          title: '学号',
          fixed: 'left',
          width:'150px',
          dataIndex: 'xh'
        },
        {
          title: '姓名',
          width:'100px',
          fixed: 'left',
          dataIndex: 'xm'
        },
        {
          title: '所属院系',
          width:'8%',
          dataIndex: 'zsyxmc'
        },
        {
          title: '所属专业',
          width:'10%',
          dataIndex: 'zszymc'
        },
        {
          title: '论文题目',
          dataIndex: 'lwtm'
        },
        {
          title: '论文主题词',
          dataIndex: 'lwztc',
          width: 200
        },
        {
          title: '刊物名称',
          dataIndex: 'kwmc'
        },
        {
          title: '影响因子',
          dataIndex: 'yxyz',
          width: 100
        },
        {
          title: '导师',
          width:'5%',
          dataIndex: 'dsxm'
        },
        {
          title: '导师审核状态',
          width:'4.5%',
          dataIndex: 'dsshztmc'
        },
        {
          title: '院系审核状态',
          width:'4.5%',
          dataIndex: 'shztmc'
        },
        {
          title: '论文发表时间',
          width:'10%',
          dataIndex: 'lwfbsj'
        }
      ],
      loadData: parameter => {
        parameter.pageNum = parameter.pageNo
        let params = Object.assign({}, this.queryParam, parameter)
        DateToString(params,'YYYY-MM')
        return this.$api.cultivate.paperList(params).then(res => {
          res.data.rows.map(item=>{
            item.lwfbsj = moment(item.lwfbsj).format('YYYY-MM');
          })
          return {
            data: res.data.rows,
            pageNo: parameter.pageNo,
            pageSize: parameter.pageSize,
            totalPage: Math.ceil(res.data.total / parameter.pageSize),
            totalCount: res.data.total
          }
        })
      },
      selectMenu: {}
    }
  },
  components: {STable},
  computed: {
    ...mapState({
      TYPE0503: state => state.app['TYPE0503'],
      TYPE0075: state => state.app['TYPE0075']
    })
  },
  created () {
    this.$store.dispatch('app/setDictionary', 'TYPE0075')
    this.$store.dispatch('app/setDictionary', 'TYPE0503')
    this.initSelectMenu()
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yxList: res[0].data
        }
      })
    },
    filterOption (value, op) {
      return op.componentOptions.children[0].text.indexOf(value) !== -1
    },
    yxChange (code) {
      this.$set(this.queryParam, 'zyh', '')
      if (code) {
        this.$api.base.majorAll({lsdwh: code}).then(res => {
          this.$set(this.selectMenu, 'zyList', res.data)
        })
      } else {
        this.$set(this.selectMenu, 'zyList', [])
      }
    },
    exportExcel () {
      let params = {...this.queryParam}
      delete params.pageNum
      this.$export('/foster/lwxx/listExport', params)
    }
  }
}
</script>

<style>

</style>
